<?php
class Award extends AppModel {
	var $name = 'Award';
	
	var $validate = array(
		'member_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'date' => array(
			'date' => array(
				'rule' => array('date'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'category_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'activity_description' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'A description of the activity this award is for is required'
			),
		),
		'general' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'regional' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'national' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'member_location_id' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Member location is required'
			)
		),
		'location_id' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Location is required'
			)
		),
		'location_performed_id' => array(
			'notempty' => array(
				'rule' => array('notempty'),
				'message' => 'Location peformed is required'
			)
		),
		'recommended_at_url' => array(
			'recommended_at_urlRequired' => array(
				'rule' => array('_recommended_at_urlRequired'),
				'message' => 'If award location differs from award performed location, a url pointing to the award recommendation is required'
			)
		)
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Member' => array(
			'className' => 'Member',
			'foreignKey' => 'member_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Category' => array(
			'className' => 'Category',
			'foreignKey' => 'category_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'RecommendedBy' => array(
			'className' => 'Member',
			'foreignKey' => 'recommended_by_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'ApprovedBy' => array(
			'className' => 'Member',
			'foreignKey' => 'approved_by_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'MemberLocation' => array(
			'className' => 'Location',
			'foreignKey' => 'member_location_id'
		),
		'Location' => array(
			'className' => 'Location',
			'foreignKey' => 'location_id'
		),
		'PerformedLocation' => array(
			'className' => 'Location',
			'foreignKey' => 'location_performed_id'
		)
	);
	
	protected function _recommended_at_urlRequired($check) {
		if ($this->data['Award']['location_id'] == $this->data['Award']['location_performed_id']) {
			return true;
		} else if (!empty($check['recommended_at_url'])) {
			return Validation::url($check['recommended_at_url']);
		}
		return false;
	}
}
?>